﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTOMall;
using DAOMall;
using BLLMall;

namespace MallProject.Admin.View
{
    public partial class Feedback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (IsPostBack == false)
            {

                Databound();

            }
        }
        public void Databound()
        {
            FeedbackDTO fb = new FeedbackDTO();
            grfeed.DataSource = fb.getAll();
            grfeed.DataBind();

        }

        protected void grfeed_ItemDataBound(object sender, DataGridItemEventArgs e)
        {

        }

        protected void grfeed_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            grfeed.CurrentPageIndex = e.NewPageIndex;
            Databound();
        }

        protected void grfeed_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            FeedbackDTO fb = new FeedbackDTO();
            Feedback f = new Feedback();
            string command = e.CommandName;
            int Fid = Convert.ToInt32(e.CommandArgument);
            if (command.Equals("Edit"))
            {

                Multi.ActiveViewIndex = 1;
                f = (Feedback)fb.getByID(Fid);
            }
            else
            {
                if (command.Equals("Delete"))
                {
                    Boolean check = fb.delete(Fid);
                    String Notic = "";
                    Notic = (check == true) ? "Delete succes" : "Cannot delete this item";
                    Response.Write("<script>alert('" + Notic + "')</script>");
                    Databound();
                    Multi.ActiveViewIndex = 0;
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Multi.ActiveViewIndex = 0;
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Multi.ActiveViewIndex = 0;
        }

    }
}